const app = getApp()
import {
  imageUrl
} from "../../utils/imageutil.js"
import {
  to_tim_chat
} from "../../utils/to_tim_chat"
import {
  rpxToPx
} from "../../utils/util"
import {
  is_auth
} from "../../utils/util"
let wxCharts = require('../../utils/wxcharts.js');
Page({
  data: {
    userInfo: wx.getStorageSync('userInfo'),
    authInfo: wx.getStorageSync('auntInfo'),
    statusBarHeight: app.globalData.statusBarHeight,
    titleBarHeight: app.globalData.titleBarHeight,
    windowHeight: app.globalData.windowHeight,
    textarea_h: 0,
    nav_title: '数字名片',
    myDefaultAddress: null,
    page_length: 0,
    uid: '',
    imageUrl,
    navbarInitTop: 0, //导航栏初始化距顶部的距离
    isFixedTop: false, //是否固定顶部
    navbarcurr: 1,
    navbarlist: [{
      title: '介绍',
      id: 1
    }, {
      title: '资料',
      id: 2
    }, {
      title: '评价',
      id: 3
    }, {
      title: '推荐',
      id: 4
    }],
    auntInfo: null,
    housekeeperListPage: 1,
    housekeeperListType: '',
    housekeeperListby: 3,
    housekeeperListFlag: true,
    housekeeperList: [],
    toView: '',
    scrollTop: '',
    worktime: '',
    content: '',
    showpopup: false,
    multiIndex: [0, 0, 0],
    type: '', //家政员类型
    CommentList: [], //评论列表
    is_newshow: false, //新弹窗
    Goods_Num: 1, //数量
    aunt_money: 0, //家政员价格
    all_money: '', //总价
    desc_money: '', //其他价格说明
    iscard: false,
    cardlist: [], //我的会员卡卡信息
    hyid: '', //会员id
    is_simple_member: '', //是否幸福会员
    is_happiness_member: '', //是否超有幸福会员
    integral_money: '', //积分抵扣
    integral: '', //服务积分
    show: false,
    cardcurr: -1,
    order_id: '',
    constellation: ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座',
      '天秤座', '天蝎座', '射手座', '摩羯座', '双鱼座', '水瓶座'
    ], //星座
    any: ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪'], //生肖
    residence: [{
      title: '是',
      is_live_room: '1'
    }, {
      title: '否',
      is_live_room: '0'
    }],
    _index: -1,
    is_live_room: '',
    wallet: '', //余额
    year_card: '', //年卡
    sea_card: '', //月卡
    mon_card: '', //季卡
    new_all_money: '', //提交订单显示的金额
    is_happiness_integral: false, //是否使用幸福指数
    is_integral: false, //是否使用服务指数
    uer_integral: 0, //抵扣的服务指数
    user_happiness_integral: 0, //抵扣的幸福指数
    show_uer_integral: false,
    show_user_happiness_integral: false,

    uer_integral_num: 0,
    user_happiness_integral_num: 0,
    income: 0, //余额
    is_income: false, //是否使用余额
    user_income: 0, //使用余额
    user_income_num: 0,

    // 服务流程
    ser_list: [{
      title: '1.在线预约',
      icon: imageUrl + '/aunt/icon1.png'
    }, {
      title: '2.匹配面试',
      icon: imageUrl + '/aunt/icon2.png'
    }, {
      title: '3.下单支付',
      icon: imageUrl + '/aunt/icon3.png'
    }, {
      title: '4.预约时间',
      icon: imageUrl + '/aunt/icon4.png'
    }, {
      title: '5.上门服务',
      icon: imageUrl + '/aunt/icon5.png'
    }, {
      title: '6.完成评价',
      icon: imageUrl + '/aunt/icon6.png'
    }],

    gqm: '', //签名地址

    languages: [],
    skill: [],
    wid: '',
    hjprice: '', //接口返回的金额
    baoxian: false, //购买保险
    bxdk_price: 0,
    hydk_price: 0,
    sxdk_price: 0,
    bxMoney: 0,
    baoxian_info: null,
    shareShow: false,
    is_radio: 2,
    shareRate: '',
    inputShare: '',
    is_server: false,
    server_money: 0,
    fw_money: '',
    fw_uid: '',
    ishy: 0,
    use_price: 0,
    hyrice: 0, //会员卡价格
    user_price: 0, //接口返回的余额抵扣会员卡的钱
    is_show_list: [{
        title: '是',
        value: 1
      },
      {
        title: '否',
        value: 2
      }
    ],
    onShowIP: 1,
    pagesInfo: [],
    pagesIndex: 0,
    pagesTc: [],
    img1: imageUrl + '/aunt/Slice331.png',
    img2: imageUrl + '/aunt/Slice330.png',
    combo_id: '', //套餐idid
    pagesPrice: 0,
    topInfo: [],
    topIndex: '',
    topIndexPage: [],
    pageDetile: [],
    topID: '',
    serviceTop: [],
    serviceId: '',
    serviceInfo: [],
    serviceTopIndex: '',
    curr: 0,
    combo_id_id: '', //套餐ABC
    all_id_price: 0,
    combo_set_id: [],
    combo_money: '',
    xzArry: [],

    paytype_list: [],
    has_jump: false,
    show_code_img: false,
    canvas_h: 300,
    canvas_w: 600,
    ay_month: []

  },

  get_paytype() {
    getApp().globalData.post({
      url: '/api/applet.oyc/paytype.html',
      data: {
        houseid: this.data.uid
      }
    }, true).then(res => {
      if (res.data.code == 1) {
        this.setData({
          paytype_list: res.data.data
        })
       
      } else {
        getApp().showModal(res.data.msg)
      }

    })
  },


  //分享
  handleShare() {
    this.setData({
      shareShow: true
    })
  },
  handleTopIndex(e) {
    this.setData({
      topIndex: e.currentTarget.dataset.id
    })
    this.handeSelctTop()
  },

  // 用户选择套餐
  handeSelctTop(e) {
    getApp().globalData.posts('/index.php/api/ouyoung/chat/sorting/ouyapi/is_combo_set', {
      id: this.data.topIndex
    }).then(res => {
      this.setData({
        topIndexPage: res.data.data,
        topID: res.data.data[this.data.pagesIndex].id,
        aunt_money: Math.ceil(res.data.data[this.data.pagesIndex].price)
      })
      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
    })
  },
  block_data_statistics() {
    getApp().globalData.posts('/api/app/wallet/sorting/ouyapi/block_data_statistics.html').then(res => {
      let data = res.data.data
      let categories = data.x.map(function (item, index) {
        return item + '\n1';
      });
      let lineChart = new wxCharts({
        canvasId: 'lineCanvas',
        type: 'column',
        categories: categories,
        animation: true,
        // background: '#f5f5f5',
        series: [{
          name: data.y,
          color: '#fc7112',
          data: data.y,
          format: function (val) {
            return Number(val)
          }
        }],
        xAxis: {
          disableGrid: true, // 禁用网格线
          type: 'calibration' // 标签校准类型
        },
        yAxis: {
          title: '',
          format: function (val) {
            return val.toFixed(2);
          },
          disabled: true,
          max: 31,
          min: 0
        },
        width: this.data.canvas_w,
        height: this.data.canvas_h,
        dataLabel: false,
        dataPointShape: true,

        extra: {
          lineStyle: 'curve',
          legendTextColor: '#fc7112'
        }
      });
    })
  },

  //选择套餐
  getTopPage(e) {
    this.setData({
      pagesIndex: e.currentTarget.dataset.index,
      topID: e.currentTarget.dataset.id,
      aunt_money: Math.ceil(e.currentTarget.dataset.price)
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  handleSelectPages(e) {
    this.setData({
      pagesIndex: e.currentTarget.dataset.index,
      pagesTc: this.data.pagesInfo[e.currentTarget.dataset.index],
      combo_id_id: e.currentTarget.dataset.id,
      pagesPrice: e.currentTarget.dataset.price,
      topID: '',
      aunt_money: Math.ceil(e.currentTarget.dataset.price)
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  //数字ip
  handleIp() {
    this.setData({
      onShowIP: 1,
      topID: '',
      combo_id_id: '',
      combo_id: '',
      combo_set_id: '',
      combo_money: '',
      aunt_money: this.data.auntInfo.wages
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  //
  getTopInfo() {
    getApp().globalData.posts('/index.php/api/ouyoung/chat/sorting/ouyapi/auth_combo_type_left').then(res => {
      this.setData({
        topInfo: res.data.data,
        topIndex: res.data.data[0].id
      })
      this.handeSelctTop()
    })
  },
  //阿姨档期
  getay_month() {
    getApp().globalData.post({
      url: '/api/applet.oyc/ay_month',
      data: {
        to_uid: this.data.uid
      }
    }, true).then(res => {
      let ay_month = res.data.data
      ay_month.forEach((v, i) => {
        v.month = v.month.slice(5, 7)
      })
      this.setData({
        ay_month
      })

    })
  },
  //   https://cyxfht.xfyh4k5.com/api/applet.oyc/ay_month
  // 阿姨12个月工作天数
  // to_uid   阿姨id
  //数字套餐
  handlePages() {
    this.getTopInfo()
    this.setData({
      onShowIP: 2,
      combo_id_id: ''
    })
    this.getTopInfo()


  },
  //家政员自选的数字套餐
  handleAuthPages() {
    this.setData({
      onShowIP: 4,
      topID: ''
    })
    getApp().globalData.posts('/index.php/api/ouyoung/chat/sorting/ouyapi/is_combo', {
      id: this.data.auntInfo.id,
    }).then(res => {
      this.setData({
        pagesInfo: res.data.data,
        pagesTc: res.data.data[0],
        combo_id_id: res.data.data[0].id,
        pagesPrice: res.data.data[0].price,
        aunt_money: Math.ceil(res.data.data[0].price),
        pagesIndex: 0,

      })

      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
    })
  },
  handleService() {
    this.setData({
      onShowIP: 3,

    })
    getApp().globalData.posts('/index.php/api/ouyoung/chat/sorting/ouyapi/auth_combo_type_left').then(res => {
      this.setData({
        serviceTop: res.data.data,
        serviceId: res.data.data[0].id
      })
      let listLeft = this.data.serviceTop
      listLeft.forEach((v, i) => {
        v.list = []
        v.allAuthMoney = 0
        v.heqiong = []
      })
      this.setData({
        serviceTop: listLeft
      })

      this.getServiceInfo()
    })
  },
  handleServiceIndex(e) {
    this.setData({
      serviceId: e.currentTarget.dataset.id,
      curr: e.currentTarget.dataset.curr,
    })
    this.getServiceInfo()
  },
  checkboxChange(e) {
    let curr = this.data.curr;
    let value = e.detail.value;

    let val = 'serviceTop[' + curr + '].list'
    let auntMoneyList = 'serviceTop[' + curr + '].allAuthMoney'
    let heqiongs = 'serviceTop[' + curr + '].heqiong'
    let list = this.data.serviceTop[curr].list;
    let allAuthMoney = 0
    let heqiong = [];
    let allID = [];
    let allNumMoney = 0
    list.forEach((v, i) => {
      v.checked = false

      value.forEach((vv, ii) => {
        if (vv == v.id) {
          v.checked = true
          allAuthMoney += Number(v.price)
          heqiong.push(v.id)
          // allAuthMoney:
        }
      })
    })
    this.setData({
      [val]: list,
      [auntMoneyList]: allAuthMoney,
      [heqiongs]: heqiong

    })
    this.data.serviceTop.forEach((item, index) => {
      allID = allID.concat(item.heqiong)
      allNumMoney += Number(item.allAuthMoney)

    })
    this.setData({
      combo_set_id: allID,
      aunt_money: allNumMoney + Number(this.data.all_id_price),
      combo_money: allNumMoney + Number(this.data.all_id_price)
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
    console.log(this.data.combo_id_id, this.data.all_money, 'JIE');

  },
  getServiceInfo(e) {
    if (this.data.serviceTop[this.data.curr].list.length > 0) {
      return
    }
    getApp().globalData.posts('/index.php/api/ouyoung/chat/sorting/ouyapi/auth_combo_type', {
      id: this.data.serviceId
    }).then(res => {
      this.setData({
        serviceInfo: res.data.data
      })
      let val = 'serviceTop[' + this.data.curr + '].list'
      this.setData({
        [val]: res.data.data
      })
    })
  },
  inputShare(e) {
    this.setData({
      inputShare: e.detail.value
    })
  },
  change_is_show(e) {
    this.setData({
      is_radio: e.detail.value
    })
    if (e.detail.value == 1) {
      this.setData({
        inputShare: 10
      })
    } else {
      this.setData({
        inputShare: ''
      })
    }
  },
  getType2() { //技能
    let data = {
      distinguish: 4,
      pid: 0
    }
    return new Promise((reslove, reject) => {
      let that = this
      getApp().globalData.gets('/api/store/aunt/type', data).then(res => {
        this.setData({
          skill: res.data.data
        })
        reslove()
      })
    })
  },
  getType5() { //语言
    let data = {
      distinguish: 6,
      pid: 0
    }
    return new Promise((reslove, reject) => {
      getApp().globalData.gets('/api/store/aunt/type', data).then(res => {
        this.setData({
          languages: res.data.data
        })
        reslove()
      })
    })
  },
  //接口调用
  GetDkprice() {
    let num = Number(this.data.aunt_money * this.data.Goods_Num * 0.1)
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: 'GetDkprice',
          uid: wx.getStorageSync('userInfo').id,
          price: (Number(this.data.aunt_money) * Number(this.data.Goods_Num)).toFixed(2),
          is_happiness_integral: this.data.is_happiness_integral ? 1 : 2,
          is_integral: this.data.is_integral ? 1 : 2,
          is_income: this.data.is_income ? 1 : 0,
          bprice: this.data.bxMoney,
          hyprice: this.data.hyrice,
          sxprice: this.data.is_simple_member || this.data.hyrice > 0 ? 0 : num
        }
      }).then(res => {
        this.setData({
          uer_integral: res.data.data.integral_price,
          user_happiness_integral: res.data.data.happiness_integral_price,
          uer_integral_num: res.data.data.integral,
          user_happiness_integral_num: res.data.data.happiness_integral,
          user_income: res.data.data.income_price,
          user_income_num: res.data.data.income,
          hjprice: res.data.data.price,
          use_price: res.data.data.income_price,
          bxdk_price: Number(res.data.data.bxdk_price), //保险
          hydk_price: Number(res.data.data.hydk_price), //会员
        })
        if (res.data.data.sxdk_price) {
          this.setData({
            sxdk_price: Number(res.data.data.sxdk_price)
          })
        } else {
          this.setData({
            sxdk_price: 0
          })
        }
        reslove()
      })
    })
  },

  // 金额计算
  getshowmoney() {

    let server_moneyRate = Number(this.data.aunt_money * (this.data.server_money / 100))
    let user_money = 0;
    console.log(server_moneyRate);
    if (this.data.is_happiness_integral) {} else {
      this.setData({
        user_happiness_integral: 0
      })
    }
    if (this.data.is_integral) {

    } else {
      this.setData({
        uer_integral: 0
      })
    }
    user_money = Number(this.data.user_happiness_integral + this.data.uer_integral + this.data.user_income + this.data.bxdk_price + this.data.hydk_price + this.data.sxdk_price).toFixed(2)
    if (this.data.cardcurr == -1) {
      //未选会员卡
      if (this.data.is_simple_member) {
        console.log("会员1");
        this.setData({
          all_money: Number((this.data.aunt_money * this.data.Goods_Num) + server_moneyRate + this.data.ishy - user_money).toFixed(2),
          desc_money: "已优惠￥" + user_money
        })
      } else {
        console.log("会员2");
        this.setData({
          all_money: Number(((this.data.aunt_money * this.data.Goods_Num) + (this.data.aunt_money * this.data.Goods_Num * 0.1)) + server_moneyRate + this.data.ishy + this.data.bxdk_price - user_money).toFixed(2),
          desc_money: "含手续费10%"
        })
      }
    } else if (this.data.cardcurr == 0 || this.data.cardcurr == 1) {
      // 幸福会员
      console.log("会员3");
      if (this.data.is_simple_member) {
        this.setData({
          all_money: (this.data.aunt_money * this.data.Goods_Num) + server_moneyRate + this.data.ishy - user_money,
          desc_money: ""
        })
      } else {
        console.log("会员4");
        this.setData({
          all_money: Number(this.data.aunt_money * this.data.Goods_Num) + Number(this.data.cardlist[this.data.cardcurr].list[0].price) + server_moneyRate + this.data.ishy + this.data.sxdk_price - user_money,
          desc_money: "含 ¥" + this.data.cardlist[this.data.cardcurr].list[0].price + this.data.cardlist[this.data.cardcurr].title
        })
      }
    } else {
      console.log("会员5");
      // 超有幸福会员
      if (this.data.is_happiness_member) {
        this.setData({
          all_money: (this.data.aunt_money * this.data.Goods_Num) + server_moneyRate + this.data.ishy - user_money,
          desc_money: ""
        })
      } else {
        this.setData({
          all_money: Number(this.data.aunt_money * this.data.Goods_Num) + Number(this.data.cardlist[this.data.cardcurr].list[0].price) + server_moneyRate + this.data.ishy - user_money,
          desc_money: "含 ¥" + this.data.cardlist[this.data.cardcurr].list[0].price + this.data.cardlist[this.data.cardcurr].title
        })
      }
    }
  },
  confirm() {
    this.setData({
      show: false
    })
    this.to_insurance('store')
  },
  getintegral() {
    getApp().globalData.gets('/api/user/no_get_coupon/' + this.data.order_id, {}, true, {
      'XU-Token': wx.getStorageSync('ay_token')
    }).then(res => {
      if (res.data.status == 200 && res.data.data != '') {
        this.setData({
          show: true,
          list: res.data.data
        })
      } else {
        wx.reLaunch({
          url: '../order/order',
        })
      }
    })
  },

  // 家政员金额
  aunt_money_minus() {
    let num = this.data.aunt_money;
    if (num >= 2) {
      num--
    } else {
      wx.showToast({
        title: '不能再减少了哟！',
        icon: 'none'
      })
    }
    this.setData({
      aunt_money: num
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  aunt_money_add() {
    let num = this.data.aunt_money;
    num++
    this.setData({
      aunt_money: num
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  change_aunt_money() {
    wx.showModal({
      title: '请输入家政员价格',
      editable: true,
      placeholderText: '请输入家政员价格',
      content: this.data.aunt_money + '',
      success: (res) => {
        if (res.confirm) {
          let regPos = /^\d+(\.\d+)?$/;
          if (regPos.test(res.content)) {
            if (res.content == 0) {
              wx.showToast({
                title: '请输入大于0的金额',
                icon: 'none'
              })
            } else {
              this.setData({
                aunt_money: Math.ceil(res.content)
              })
              this.GetDkprice().then(() => {
                this.getshowmoney()
              })
            }
          } else {
            wx.showToast({
              title: '请输入大于0的金额',
              icon: 'none'
            })
          }
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 服务数量
  addNum() {
    let num = this.data.Goods_Num
    num++
    this.setData({
      Goods_Num: num
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  minusNum() {
    let num = this.data.Goods_Num
    if (num >= 2) {
      num--
    } else {
      wx.showToast({
        title: '不能再减少了哟！',
        icon: 'none'
      })
    }
    this.setData({
      Goods_Num: num
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  change_iscard(e) {
    this.setData({
      iscard: !this.data.iscard
    })
    if (this.data.iscard) {
      this.getshowmoney()

    } else {
      this.setData({
        hyrice: 0
      })
      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
      this.setData({
        cardcurr: -1,
        hyid: ''
      })
      this.getshowmoney()
    }

  },
  change_iscards(e) {
    this.setData({
      iscard: !this.data.iscard
    })

    this.setData({
      hyrice: 0
    })


  },
  // 获取会员卡状态
  getMembershipList() {
    app.globalData.post({
      data: {
        do: 'MembershipList',
        uid: wx.getStorageSync('userInfo').id
      }
    }).then(res => {
      this.setData({
        cardlist: res.data.result
      })
    })
  },

  GetBasicUserinfo() {
    app.globalData.post({
      data: {
        a: 'wxapp2',
        do: 'GetBasicUserinfo',
        uid: wx.getStorageSync('userInfo').id
      }
    }).then(res => {
      this.setData({
        is_simple_member: res.data.data.member_type, // 1 = 会员 0 = 非会员
        integral: res.data.data.integral, //服务指数
        happiness_integral: res.data.data.happiness_integral, //幸福指数
      })
    })
  },

  getGetUserCleanGift() { //判断是否会员
    let server_moneyRate = Number(this.data.aunt_money * (this.data.server_money / 100))
    this.setData({
      show_user_happiness_integral: false,
      show_uer_integral: false,
      is_happiness_integral: false,
      is_integral: false,
      iscard: false,
      hyid: '',
      cardcurr: -1,
      hyid: ''
    })
    app.globalData.post({
      data: {
        do: 'GetUserCleanGift',
        uid: wx.getStorageSync('userInfo').id
      }
    }).then(res => {
      this.setData({
        income: res.data.result.income
      })
      if (res.data.result.is_simple_member != 0 || res.data.result.is_happiness_member != 0) {
        this.setData({
          integral: Number(res.data.result.integral), //服务指数
          happiness_integral: Number(res.data.result.happiness_integral), //幸福指数
          is_simple_member: res.data.result.is_simple_member, //是否幸福会员
          is_happiness_member: res.data.result.is_happiness_member, //是否超有幸福会员
          wallet: res.data.result.wallet,
          year_card: res.data.result.year_card,
          sea_card: res.data.result.sea_card,
          mon_card: res.data.result.mon_card,
        })
      } else {
        this.setData({
          integral: Number(res.data.result.integral), //服务指数
          happiness_integral: Number(res.data.result.happiness_integral), //幸福指数
          is_simple_member: res.data.result.is_simple_member, //是否幸福会员
          is_happiness_member: res.data.result.is_happiness_member, //是否超有幸福会员
          wallet: res.data.result.wallet,
          year_card: res.data.result.year_card,
          sea_card: res.data.result.sea_card,
          mon_card: res.data.result.mon_card,
        })
      }
      if (this.data.integral > 0) {
        this.setData({
          show_uer_integral: true,
        })
      }
      if (this.data.happiness_integral > 0) {
        this.setData({
          show_user_happiness_integral: true,
        })
      }
      if (res.data.result.is_simple_member) {
        this.setData({
          all_money: (this.data.aunt_money * this.data.Goods_Num) + Number(server_moneyRate),
          desc_money: ""
        })
      } else {
        this.setData({
          all_money: Number(this.data.aunt_money * this.data.Goods_Num) + Number(this.data.aunt_money * this.data.Goods_Num) * 0.1 + Number(server_moneyRate),
          desc_money: "含手续费10%"
        })
      }
    })
  },
  // 选择会员卡
  change_cardcurr(e) {
    this.setData({
      cardcurr: e.currentTarget.dataset.index,
      hyid: e.currentTarget.dataset.id,
      hyrice: e.currentTarget.dataset.price,
      // sxdk_price:0
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })

  },
  // 下单
  new_s() {
    if (this.data.is_live_room == '') {
      wx.showToast({
        title: '住家不能为空',
        icon: 'none'
      })
      return false
    }
    this.setData({
      showpopup: true,
      nav_title: '订单提交',
      is_newshow: false
    })
    if (this.data.baoxian_info) {
      this.setData({
        bxMoney: this.data.baoxian_info.monthMoney
      })
      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
    }
    this.setData({
      new_all_money: Number(this.data.all_money)
    })
    // if(this.data.wallet>this.data.all_money){
    //   this.setData({
    //     new_all_money:'0',
    //     desc_money:''
    //   })
    // }else{
    //   let all_moneys = this.data.all_money-Number(this.data.wallet)
    //   this.setData({
    //     new_all_money:all_moneys
    //   })
    // }
  },
  // 返回按钮
  to_back() {
    if (this.data.showpopup) {
      this.setData({
        showpopup: false,
        nav_title: '数字名片',
        bxMoney: 0
      })
      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
    } else {


      wx.navigateBack({
        delta: 1,
      })

    }
  },
  to_index() {
    wx.reLaunch({
      url: '../index/index',
    })
  },
  onLoad(options) {
    this.setData({
      canvas_h: rpxToPx(346),
      canvas_w: rpxToPx(616),
    })
    wx.removeStorageSync('baoxian_info')
    wx.removeStorageSync('qm_src')
    this.setData({
      userInfo: wx.getStorageSync('userInfo')
    })
    if (wx.getStorageSync('baoxian_info')) {
      this.setData({
        bxMoney: wx.getStorageSync('baoxian_info').monthMoney
      })
    } else {
      this.setData({
        bxMoney: 0
      })
    }
    let date = new Date()
    const month = date.getMonth()
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    this.setData({
      uid: options.uid,
      multiIndex: [0, month, day - 1],
      page_length: getCurrentPages().length,
      textarea_h: wx.getSystemInfoSync().screenHeight
    })
    this.gethousekeeperInfo().then(() => {
      this.getGetUserCleanGift();
      this.getType2().then(() => {
        let skillarr = this.data.auntInfo.skill.split(',')
        let skill_val = ""
        this.data.skill.forEach((v, i) => {
          skillarr.forEach((vv, ii) => {
            if (v.id == vv) {
              if (skill_val == '') {
                skill_val = v.title
              } else {
                skill_val = skill_val + ',' + v.title
              }
            }
          })
        })
        this.setData({
          ['auntInfo.skill_val']: skill_val
        })
      })
      this.getType5().then(() => {
        let languages_arr = this.data.auntInfo.lang.split(',')
        let languages_txt = []
        this.data.languages.forEach((v, i) => {
          languages_arr.forEach((vv, ii) => {
            if (vv == v.id) {
              languages_txt.push(v.title)
            }
          })
        })
        this.setData({
          ['auntInfo.lang_val']: languages_txt.join(',')
        })
      })
    })
    this.gethousekeeperList();
    this.getCommentList();
    this.getMembershipList();
    // this.getshowmoney()

    // this.GetBasicUserinfo()
    if (options.is_radio == 1) {
      // shareRate
      this.setData({
        is_server: true,
        server_money: Number(options.shareRate),
      })
    }
    this.setData({
      fw_money: options.fw_money,
      fw_uid: options.fw_uid,

    })

    if (options.type) {
      this.setData({
        type: options.type
      })
    }
    this.block_data_statistics()
    this.getay_month()
    // this.getTopInfo()

    this.get_paytype()


  },
  onShow() {
    wx.getStorageSync('id')
    this.MyAddressInfo()
    if (this.data.has_jump) {
      getApp().showModal('是否已完成支付', true).then(() => {
        wx.reLaunch({
          url: '../order/order'
        })
      })
      this.setData({
        has_jump: false
      })
    }
    if (wx.getStorageSync('qm_src')) {
      this.setData({
        gqm: wx.getStorageSync('qm_src')
      })
    }
    if (wx.getStorageSync('baoxian_info')) {
      this.setData({
        baoxian_info: wx.getStorageSync('baoxian_info'),
        bxMoney: wx.getStorageSync('baoxian_info').monthMoney
      })
      this.GetDkprice().then(() => {
        this.getshowmoney()
      })
      wx.removeStorageSync('baoxian_info')
    } else {
      if (!this.data.nav_title == '订单提交') {
        this.setData({
          bxMoney: 0
        })
      }

    }
    this.setData({
      textarea_h: wx.getSystemInfoSync().screenHeight
    })
  },
  close_baoxian() {
    this.setData({
      baoxian_info: null,
      bxMoney: 0
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  MyAddressInfo() { //选择地址
    getApp().globalData.post({
      data: {
        do: "MyAddressInfo",
        id: wx.getStorageSync('id')
      }
    }).then(res => {
      this.setData({
        myDefaultAddress: res.data
      })
    })
  },
  getCommentList() {
    app.globalData.post({
      data: {
        do: 'CommentList',
        uid: this.data.uid
      }
    }).then(res => {
      this.setData({
        CommentList: res.data.data.list
      })
    })
  },
  toMyAddress() {
    wx.navigateTo({
      url: '../my/address?type=1',
    })
  },

  to_baoxian() {
    wx.navigateTo({
      url: '/insurance/select_baoxian',
    })
  },

  removes() {
    this.setData({
      showpopup: false
    })
  },
  gets() {
    if (this.data.worktime == "") {
      wx.showToast({
        title: '请选择上门时间',
        icon: "none"
      })
      return false;
    }
    if (this.data.gqm == "") {
      wx.showToast({
        title: '请先签名',
        icon: "none"
      })
      return false;
    }
    if (this.data.addressid == "") {
      wx.showToast({
        title: '请添加服务地址',
        icon: "none"
      })
      return false;
    }
    // if (!this.data.baoxian_info) {
    //   wx.showToast({
    //     title: '请添加保险方案',
    //     icon: "none"
    //   })
    //   return false;
    // }
    let baoxian_obj = {}
    if (this.data.baoxian_info) {
      baoxian_obj = {
        bx_money: this.data.baoxian_info.monthMoney,
        caseCode: this.data.baoxian_info.caseCode,
        day_type: this.data.baoxian_info.day_type ? this.data.baoxian_info.day_type : 1,
      }
      this.setData({
        bxMoney: this.data.baoxian_info.monthMoney
      })
    }
    app.globalData.post({
      data: {
        do: 'AddReleaseWork4',
        uid: wx.getStorageSync('userInfo').id,
        to_uid: this.data.auntInfo.id,
        type: this.data.type == '' ? (this.data.auntInfo.work_type.split(",")[0]) : this.data.type,
        addressid: this.data.myDefaultAddress.id,
        worktime: this.data.worktime,
        content: this.data.content,
        hyid: this.data.hyid,
        fw_money: this.data.fw_money,
        fw_uid: this.data.fw_uid,
        money: this.data.aunt_money,
        integral_money: this.data.uer_integral, //服务指数
        happiness_integral: this.data.user_happiness_integral, //幸福指数
        quantity: this.data.Goods_Num,
        // use_wallet_money:1,//我的余额
        is_live_room: this.data.is_live_room,
        is_integral: this.data.is_integral ? 1 : 2,
        is_happiness_integral: this.data.is_happiness_integral ? 1 : 2,
        gqm: this.data.gqm,
        start_day: this.data.worktime,
        combo_id: this.data.topID,
        combo_id_id: this.data.combo_id_id,
        combo_set_id: this.data.combo_set_id,
        combo_money: this.data.combo_money,
        ...baoxian_obj
      }
    }).then(res => {
      let wid = res.data.data;
      this.setData({
        wid
      })
      let status = res.data.status
      if (status == 2) {
        this.to_insurance()
      } else if (status == 0) {
        getApp().showModal(res.data.msg)
      } else {
        this.pay(wid)
      }
    })
  },
  getcontent(e) {
    this.setData({
      content: e.detail.value
    })
  },
  getTime(e) {
    this.setData({
      worktime: e.detail
    })
  },
  to_gqm() {
    if (!this.data.worktime) {
      wx.showToast({
        title: '请先选择上门时间',
        icon: 'none'
      })
      return
    }
    if (!this.data.myDefaultAddress.id) {
      wx.showToast({
        title: '请先选择服务地址',
        icon: 'none'
      })
      return
    }
    wx.navigateTo({
      url: '/pages/aunt/handwriting/handwriting?qm=true&id=' + this.data.auntInfo.id + '&addr_id=' + this.data.myDefaultAddress.area.join('') + this.data.myDefaultAddress.address + this.data.myDefaultAddress.doorplate + '&worktime=' + this.data.worktime + '&is_live_room=' + this.data.is_live_room,
    })
  },
  changenavbarcurr(e) {
    this.setData({
      navbarcurr: e.currentTarget.dataset.id
    })
  },
  change_focus(e) {
    this.setData({
      textarea_h: wx.getSystemInfoSync().screenHeight - e.detail.height
    })
  },
  change_blur(e) {
    this.setData({
      textarea_h: wx.getSystemInfoSync().screenHeight,
      content: e.detail.value
    })
  },
  gethousekeeperInfo() {
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: 'housekeeperInfo',
          uid: this.data.uid,
          to_uid: wx.getStorageSync('userInfo').id,
        }
      }).then(res => {
        let xzArry = []
        let medal = res.data.data.medal
        if (medal) {
          xzArry = medal.split(',')
        }
        this.setData({
          xzArry,
          auntInfo: res.data.data,
          aunt_money: res.data.data.wages,
          hjprice: res.data.data.wages,
          all_id_price: res.data.data.wages,
        })
        console.log(this.data.xzArry.indexOf('1'), '55');
        if (typeof (this.data.auntInfo.pic) == 'string') {
          this.setData({
            ['auntInfo.pic']: this.data.auntInfo.pic.split(',')
          })
        }
        reslove()
      })
    })
  },
  gethousekeeperList() {
    app.globalData.post({
      data: {
        do: 'housekeeperList',
        uid: wx.getStorageSync('userInfo').id,
        page: this.data.housekeeperListPage,
        by: this.data.housekeeperListby,
        pagesize: 10,
        type: this.data.housekeeperListType
      }
    }).then(res => {
      wx.stopPullDownRefresh();
      if (res.data.data.length == 0) {
        this.setData({
          housekeeperListFlag: false
        })
      } else {
        let arr = this.data.housekeeperList.concat(res.data.data);
        this.setData({
          housekeeperList: arr,
          housekeeperListPage: this.data.housekeeperListPage + 1
        })
      }
    })
  },
  Collection() {
    app.globalData.post({
      data: {
        do: 'Collection',
        uid: wx.getStorageSync('userInfo').id,
        to_uid: this.data.uid
      }
    }).then(res => {
      this.setData({
        ['auntInfo.collection']: res.data.data
      })
    })
  },
  to_hyqy() {
    wx.navigateTo({
      url: '../my/hyqy',
    })
  },
  close_newshow() {
    this.setData({
      is_newshow: false,
    })
  },
  btns() {
    // if(this.data.auntInfo.uid==0){
    //   app.showModal('见习家政员不能下单！')
    //   return
    // }
    if (is_auth(true)) {
      this.setData({
        is_newshow: true,
      })


    }
  },
  pay(id) {
    let paytype_list = this.data.paytype_list
    let itemList = []
    paytype_list.forEach((v, i) => {
      itemList.push(v.title)
    })
    wx.showActionSheet({
      itemList,
      success: (res) => {
        let tapIndex = res.tapIndex
        let paytype = paytype_list[tapIndex].paytype
        if (paytype == 6) {
          wx.setStorageSync('pay_info', {
            do: 'pay',
            order_id: id,
            user_id: wx.getStorageSync('userInfo').id,
            openid: wx.getStorageSync('userInfo').openid,
            type: 4,
            paytype,
            is_integral: this.data.is_integral ? 1 : 2,
            is_happiness_integral: this.data.is_happiness_integral ? 1 : 2,
            is_income: this.data.is_income ? 1 : 0,
            gqm: this.data.gqm
          })
          wx.navigateTo({
            url: '/online_bank/list?id=' + id
          })
          return
        }
        app.globalData.post({
          data: {
            do: 'pay',
            order_id: id,
            user_id: wx.getStorageSync('userInfo').id,
            openid: wx.getStorageSync('userInfo').openid,
            type: 4,
            paytype,
            is_integral: this.data.is_integral ? 1 : 2,
            is_happiness_integral: this.data.is_happiness_integral ? 1 : 2,
            is_income: this.data.is_income ? 1 : 0,
            gqm: this.data.gqm
          }
        }).then(res => {
          let data = res.data
          this.setData({
            order_id: res.data.order_id
          })
          if (data.code == 0) {
            getApp().showModal(data.msg)
            return
          }
          if (data.pay_status == 2) {
            getApp().showModal('支付成功').then(() => {
              this.getintegral()
            })
            return
          }
          if (data.jump) {
            this.selectComponent('#zfb_pay').get_code(data.jump)
            this.setData({
              show_code_img: true,
              has_jump: true,
            })
            return
          } else {
            this.setData({
              has_jump: false
            })
          }
          if (getApp().globalData.appletpayves_info.work == 3) {
            getApp().payPlugin(data.orderNo).then(() => {
              getApp().showModal('支付成功').then(() => {
                this.getintegral()
              })
            }).catch(() => {
              wx.reLaunch({
                url: '../order/order'
              })
            })
            return
          }
          if (!data.package) {
            getApp().showModal('暂无法使用该支付方式，请选择其他支付方式', true).then(() => {
              this.pay(id)
            })
            return
          }
          wx.requestPayment({
            nonceStr: data.nonceStr,
            package: data.package,
            paySign: data.paySign,
            timeStamp: data.timeStamp,
            signType: data.signType,
            success: () => {
              wx.showToast({
                title: "支付成功",
                icon: "none"
              })
              this.getintegral()
            },
            fail: (e) => {
              wx.showToast({
                title: "支付失败",
                icon: "none"
              })
              wx.reLaunch({
                url: '../order/order'
              })
            }
          })
        })
      }
    })
  },
  open_hy() {

    if (this.data.userInfo.is_member == 0) {
      getApp().showModal('请先开通会员或经纪人')
      return false
    }

  },
  to_inquiry() {
    if (this.open_hy()) {
      return false
    }
    wx.navigateTo({
      url: './inquiry?aunt_id=' + this.data.auntInfo.id,
    })
  },
  to_tim() {
    if (this.open_hy()) {
      return false
    }
    to_tim_chat(this.data.auntInfo.IM)
  },
  updateInfo(e) {
    this.setData({
      uid: e.currentTarget.dataset.id,
      housekeeperListPage: 1,
      housekeeperListType: '',
      housekeeperListby: 3,
      housekeeperListFlag: true,
      housekeeperList: [],
    })
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 0
    })
    this.gethousekeeperInfo().then(() => {
      this.getGetUserCleanGift();
    })
    this.gethousekeeperList();
  },
  Share() {
    this.setData({
      shareShow: false
    })
  },
  onShareAppMessage() {
    let url = '/pages/aunt/index?uid=' + this.data.uid + '&type=1' + '&shareRate=' + this.data.inputShare + '&is_radio=' + this.data.is_radio + '&fw_uid=' + this.data.userInfo.id + '&fw_money=' + Number(this.data.aunt_money * (this.data.inputShare / 100))
    url = encodeURIComponent(url)
    let my_partner_name = ''
    if (wx.getStorageSync('my_partner_name')) {
      my_partner_name = wx.getStorageSync('my_partner_name') + ' · '
    }
    return {
      path: '/pages/index/blank?to_id=' + wx.getStorageSync('userInfo').id + '&tourl=' + url + '&is_share=true',
      title: my_partner_name + this.data.auntInfo.user_nickname,
      imageUrl: this.data.auntInfo.avatar
    }
  },
  show(e) {
    this.setData({
      _index: e.currentTarget.dataset.index,
      is_live_room: e.currentTarget.dataset.is_live_room
    })
  },

  change_happiness_integral() {
    this.setData({
      is_happiness_integral: !this.data.is_happiness_integral,
      bxMoney: 0
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  change_integral() {
    this.setData({
      is_integral: !this.data.is_integral,
      bxMoney: 0
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  //余额
  change_income() {
    this.setData({
      is_income: !this.data.is_income,
      bxMoney: 0
    })
    this.GetDkprice().then(() => {
      this.getshowmoney()
    })
  },
  getbig(e) {
    let type = e.currentTarget.dataset.type
    let src = e.currentTarget.dataset.src
    let urls = []
    if (type == 'avatar') {
      urls = [this.data.auntInfo.avatar]
    } else if (type == 'pic') {
      urls = this.data.auntInfo.pic
    } else if (type == 'certificate') {
      urls = this.data.auntInfo.certificate
    } else if (type == 'physical') {
      urls = this.data.auntInfo.physical
    }
    wx.previewImage({
      urls,
      current: src
    })
  },

  makePhoneCall() {
    if (this.open_hy()) {
      return false
    }
    getApp().phoneCall(this.data.auntInfo.store_tel)
    // wx.makePhoneCall({
    //   // phoneNumber: this.data.auntInfo.phonenumber
    //   phoneNumber:'4008726866'
    // })
  },

  to_insurance(type = 'order') {
    return new Promise((reslove, reject) => {
      getApp().globalData.post({
        data: {
          do: 'Workinfo',
          wid: this.data.wid,
        }
      }).then(res => {
        if (type == 'order') {
          wx.reLaunch({
            url: '../order/order',
          })
        } else if (type == 'store') {
          wx.reLaunch({
            url: '/store/store',
          })
        }
        return
        getApp().showModal('是否购买保险', true).then(() => {
          wx.setStorageSync('buy_bx', res.data.data)
          wx.reLaunch({
            url: '/insurance/index?order_type=' + true + '&item=' + true,
          })
        }).catch(() => {
          if (type == 'order') {
            wx.reLaunch({
              url: '../order/order',
            })
          } else if (type == 'store') {
            wx.reLaunch({
              url: '/store/store',
            })
          }
        })
      })
    })
  },

})